import java.util.Scanner;

public class Main3 {

    public static int n;
    public static long[] arr1; //酸
    public static long[] arr2; //苦
    public static long min = Integer.MAX_VALUE;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();
        arr1 = new long[n];
        arr2 = new long[n];
        for (int i = 0; i < n; i++) {
            arr1[i] = sc.nextLong();
            arr2[i] = sc.nextLong();
        }

        dfs(0, 1, 0);

        System.out.println(min);

        sc.close();
    }

    /**
     *
     * @param index
     * @param acidity 总酸度
     * @param bitter 总苦度
     */
    public static void dfs(int index, long acidity, long bitter) {
        if (index == n) {
            if (acidity != 1 || bitter != 0) {
                min = Math.min(min, Math.abs(acidity - bitter));
            }
            return;
        }

        for (int i = index; i < n; i++) {
            //选
            dfs(i + 1, acidity * arr1[index], bitter + arr2[index]);

            //不选
            dfs(i + 1, acidity, bitter);
        }
    }
}
